<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!-- namespace必须指向Mao接口 -->
<mapper namespace="cn.com.digitalnet.ad.repository.mybatis.${className}Mao">
	<select id="query" parameterType="map" resultType="${className}">
		select
			id,
			<#list fields as map>
				<#list map?keys as name>
			      ${name} as ${map[name]},
			    </#list>
			 </#list>
			   isenabled,
			    isdeleted
		from
			${tableName}
		<where>
			<include refid="whereContent"/>
		</where>
			<if test="order != null">
			order by ${r"${order}"} ${r"${orderDire}"}
			</if>
			<if test="start != null and limit != null">
				limit ${r"#{start}"}, ${r"#{limit}"}
			</if>
	</select>
	
	<select id="count" parameterType="map" resultType="int">
		select
			count(*) 
		from
			${tableName}
		<where>
			<include refid="whereContent"/>
		</where>
	</select>
	
	<sql id="whereContent">
		<if test="id != null">
			id = ${r"#{id}"}
		</if>
		
		<if test="isenabled != null">
			and isenabled = ${r"#{isenabled}"}
		</if>
		and isdeleted = 0
	</sql>
	
	<insert id="save" parameterType="${className}" useGeneratedKeys="true" keyProperty="id">
		insert into ${tableName}
		(
			<#list fields as map>
				<#list map?keys as name>
			      ${name},
			    </#list>
			 </#list>
			  isenabled,
			  isdeleted
		)
		values 
		(
			<#list fields as map>
				<#list map?keys as name>
			      	${r"#{"}${map[name]}${r"}"},
			    </#list>
			 </#list>
			 ${r"#{isenabled}"},
			    0
		)
	</insert>
	
	<update id="update" parameterType="${className}">
		update ${tableName}
		set
		<#list fields as map>
				<#list map?keys as name>
			      ${name} = ${r"#{"}${map[name]}${r"}"},
			    </#list>
			 </#list>
		isenabled = ${r"#{isenabled}"} 
		where
			id = ${r"#{id}"}
	</update>
	
	
	<update id="delete" parameterType="long">
	    update ${tableName}
		set
			isdeleted = 1
		where
			id = ${r"#{id}"}
	</update>
	
	<update id="submit" parameterType="long">
	    update ${tableName}
		set
			isenabled = 1
		where
			id = ${r"#{id}"}
	</update>
	
</mapper> 
